package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TmdDutyDatePeople;
import com.ruoyi.system.service.ITmdDutyDatePeopleService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 排班Controller
 * 
 * @author ruoyi
 * @date 2024-04-20
 */
@Controller
@RequestMapping("/system/people")
public class TmdDutyDatePeopleController extends BaseController
{
    private String prefix = "system/people";

    @Autowired
    private ITmdDutyDatePeopleService tmdDutyDatePeopleService;

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private ISysDeptService iSysDeptService;

    @GetMapping("/getPeople")
    @ResponseBody
    public List<TmdDutyDatePeople> getAllUserByApp(Long id, Model model) {
        List<TmdDutyDatePeople> allPeopleByApp = tmdDutyDatePeopleService.getAllPeopleByApp(id);
        model.addAttribute("allPeopleByApp",allPeopleByApp);
        return allPeopleByApp;
    }

    @RequiresPermissions("system:people:view")
    @GetMapping()
    public String people()
    {
        return prefix + "/people";
    }

    /**
     * 查询排班列表
     */
    @RequiresPermissions("system:people:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TmdDutyDatePeople tmdDutyDatePeople)
    {
        startPage();
        List<TmdDutyDatePeople> list = tmdDutyDatePeopleService.selectTmdDutyDatePeopleList(tmdDutyDatePeople);
        return getDataTable(list);
    }

    /**
     * 导出排班列表
     */
    @RequiresPermissions("system:people:export")
    @Log(title = "排班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TmdDutyDatePeople tmdDutyDatePeople)
    {
        List<TmdDutyDatePeople> list = tmdDutyDatePeopleService.selectTmdDutyDatePeopleList(tmdDutyDatePeople);
        ExcelUtil<TmdDutyDatePeople> util = new ExcelUtil<TmdDutyDatePeople>(TmdDutyDatePeople.class);
        return util.exportExcel(list, "排班数据");
    }

    /**
     * 新增排班
     */
    @GetMapping("/add")
    public String add(Model model)
    {
        Long id=106L;
        List<SysDept> deptList = iSysDeptService.selectAllDeptList();
        model.addAttribute("deptList",deptList);
        List<SysUser> userList=sysUserService.getAllUserByDept(id);
        model.addAttribute("userList",userList);
        return prefix + "/add";
    }

    /**
     * 新增保存排班
     */
    @RequiresPermissions("system:people:add")
    @Log(title = "排班", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TmdDutyDatePeople tmdDutyDatePeople)
    {
        System.out.println(tmdDutyDatePeople);
        return toAjax(tmdDutyDatePeopleService.insertTmdDutyDatePeople(tmdDutyDatePeople));
    }
    @PostMapping("/addDatePeople")
    @ResponseBody
    public AjaxResult addSaveDatePeopleList(List<TmdDutyDatePeople> tmdDutyDatePeople)
    {
        System.out.println(tmdDutyDatePeople);
        return toAjax(tmdDutyDatePeopleService.insertTmdDutyDatePeopleList(tmdDutyDatePeople));
    }

    /**
     * 修改排班
     */
    @RequiresPermissions("system:people:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TmdDutyDatePeople tmdDutyDatePeople = tmdDutyDatePeopleService.selectTmdDutyDatePeopleById(id);
        mmap.put("tmdDutyDatePeople", tmdDutyDatePeople);
        return prefix + "/edit";
    }

    /**
     * 修改保存排班
     */
    @RequiresPermissions("system:people:edit")
    @Log(title = "排班", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TmdDutyDatePeople tmdDutyDatePeople)
    {
        return toAjax(tmdDutyDatePeopleService.updateTmdDutyDatePeople(tmdDutyDatePeople));
    }

    /**
     * 删除排班
     */
    @RequiresPermissions("system:people:remove")
    @Log(title = "排班", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tmdDutyDatePeopleService.deleteTmdDutyDatePeopleByIds(ids));
    }
}
